package hr.ctg.domain.action.objekt;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import hr.ctg.domain.action.SlikaAction;

import hr.ctg.domain.model.Korisnik;

import hr.ctg.domain.model.Objekt;
import hr.ctg.service.dao.AdresaDAO;
import hr.ctg.service.dao.AkcijaDAO;
import hr.ctg.service.dao.CijenaDAO;
import hr.ctg.service.dao.DnevnikAktivnostiDAO;
import hr.ctg.service.dao.EmailAdresaDAO;
import hr.ctg.service.dao.MjestoDAO;
import hr.ctg.service.dao.ObjektDAO;
import hr.ctg.service.dao.OpisDAO;
import hr.ctg.service.dao.OsobinaDAO;

import hr.ctg.service.dao.PostaDAO;
import hr.ctg.service.dao.SlikaDAO;
import hr.ctg.service.dao.SmjestajDAO;
import hr.ctg.service.dao.TelefonDAO;
import hr.ctg.service.dao.TipAdreseDAO;
import hr.ctg.service.dao.TipEmailAdreseDAO;
import hr.ctg.service.dao.TipObjektaDAO;
import hr.ctg.service.dao.TipTelefonaDAO;
import hr.ctg.service.dao.ZupanijaDAO;



import org.jboss.seam.ScopeType;

import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;

import org.jboss.seam.annotations.Scope;

import org.jboss.seam.annotations.web.RequestParameter;
import org.jboss.seam.cache.CacheProvider;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Identity;
import org.richfaces.model.CalendarDataModel;
import org.richfaces.model.CalendarDataModelItem;


@Scope(ScopeType.STATELESS)
@Name(value = "objektReservation")
public class ObjektReservationAction {
	@Logger
	Log log;
	@In
	FacesMessages facesMessages;

	@In
	CacheProvider cacheProvider;
	@In
	private ObjektDAO objektDAO;
	@In
	PostaDAO postaDAO;
	@In
	MjestoDAO mjestoDAO;
	@In
	ZupanijaDAO zupanijaDAO;
	@In
	AkcijaDAO akcijaDAO;
	@In
	DnevnikAktivnostiDAO dnevnikAktivnostiDAO;
	@In
	SlikaDAO slikaDAO;
	@In
	OpisDAO opisDAO;
	@In
	TelefonDAO telefonDAO;
	@In
	AdresaDAO adresaDAO;
	@In
	EmailAdresaDAO emailAdresaDAO;
	@In
	CijenaDAO cijenaDAO;
	@In
	OsobinaDAO osobinaDAO;
	@In
	TipObjektaDAO tipObjektaDAO;
	@In
	TipAdreseDAO tipAdreseDAO;
	@In
	TipTelefonaDAO tipTelefonaDAO;
	@In
	TipEmailAdreseDAO tipEmailAdreseDAO;
	@In
	SmjestajDAO smjestajDAO;
	@In
	Identity identity;
	@In
	String currentLang;
	@In(create = true)
	SlikaAction slikaAction;

	@In(required = false)
	Korisnik korisnik;
	
	private String extraNote = null;
	private Integer childAgeCnt = null;
	private Integer adultAgeCnt = null;
	private Date dateArrival = null;
	private Date dateDeparture = null;
	private String email = null;
	private String name = null;
	

	
	@RequestParameter
	private Integer idObjekta;


	public String rezervirajSmjestaj(final String back) {
		log.debug("Zapocinjem rezervaciju smjestaja...");
		Objekt objekt = objektDAO.find(idObjekta);
		log.debug("Rezerviram objekt: "+objekt.getNaziv());
		return back;
	}


	public String getExtraNote() {
		return extraNote;
	}


	public void setExtraNote(String extraNote) {
		this.extraNote = extraNote;
	}


	public Integer getChildAgeCnt() {
		return childAgeCnt;
	}


	public void setChildAgeCnt(Integer childAgeCnt) {
		this.childAgeCnt = childAgeCnt;
	}


	public Integer getAdultAgeCnt() {
		return adultAgeCnt;
	}


	public void setAdultAgeCnt(Integer adultAgeCnt) {
		this.adultAgeCnt = adultAgeCnt;
	}


	public Date getDateArrival() {
		return dateArrival;
	}


	public void setDateArrival(Date dateArrival) {
		this.dateArrival = dateArrival;
	}


	public Date getDateDeparture() {
		return dateDeparture;
	}


	public void setDateDeparture(Date dateDeparture) {
		this.dateDeparture = dateDeparture;
	}


	public String getEmail() {
		return email;
	}


	public void setEmail(String email) {
		this.email = email;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public Integer getIdObjekta() {
		return idObjekta;
	}


	public void setIdObjekta(Integer idObjekta) {
		this.idObjekta = idObjekta;
	}
	
	public CalendarDataModel getDataModel(){
		return new CalendarDataModel() {
			
			@Override
			public Object getToolTip(Date arg0) {
				// TODO Auto-generated method stub
				return "Cemu sluzi ovaj tooltip?";
			}
			
			@Override
			public CalendarDataModelItem[] getData(Date[] arg0) {
				List<CalendarDataModelItem> items = new ArrayList<CalendarDataModelItem>();
				log.error("dohvat rezerviranih datuma...");
				log.error(arg0.toString());
				for(Date d:arg0){
					items.add(new CTGItemImpl(d));
				}
				log.error(items.toString());
				return items.toArray(new CalendarDataModelItem[items.size()]);
			}
		};
	}
	
	
	public class CTGItemImpl implements CalendarDataModelItem{
		public final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
		private Date date;
		private boolean enabled;
		public CTGItemImpl(Date d){
			this.date=d;
			this.enabled = true;
		}
		@Override
		public boolean isEnabled() {
			// TODO Auto-generated method stub
			return enabled;
		}
		
		@Override
		public boolean hasToolTip() {
			// TODO Auto-generated method stub
			return true;
		}
		
		@Override
		public Object getToolTip() {
			// TODO Auto-generated method stub
			return null;
		}
		
		@Override
		public String getStyleClass() {
			// TODO Auto-generated method stub
			return "rich-calendar-today";
		}
		
		@Override
		public int getDay() {
			// TODO Auto-generated method stub
			return 0;
		}
		
		@Override
		public Object getData() {
			return sdf.format(date);
		}
	}
	
	
}
